<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>视频教学网</title>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../css/userlogin.css" media="all">
	</head>
	<body>
		<div id="container">
			<div class="top">
				<div class="icon_box">
					<div>视频教学网</div>
					<div>www.videostudy.com</div>
				</div>

				<div class="tip">
					<button onclick="register()" style="cursor: pointer; color: #1E9FFF;border: none;background-color: #f5f7fa">点此进入注册</button>
				</div>
			</div>
			<div id="main">
				<div id="inner_box">
					<div><img src="../img/img1.png"></div>
					<div>
						<div>
							<form class="layui-form" action="">
								<div class="layui-form-item">
									<input type="text" name="username"  lay-verify="title" autocomplete="off" placeholder="请输入用户名或手机号" class="layui-input" style="height: 56px;">
								</div>
								<div class="layui-form-item">
									<input type="password" name="password" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input" style="height: 56px;">
								</div>
								<div class="layui-form-item input-item" id="imgCode">

									<input type="text" placeholder="请输入验证码" autocomplete="off" id="code" name="code"  class="layui-input">
									<img src="../code"  onclick="changeCode()" id="codeImg">
								</div>
								 <button type="button" class="layui-btn layui-btn-lg layui-btn-normal fill"lay-filter="login"  lay-submit>登录</button>
							</form>
							<div class="top">
								<div class="nowrap"><button onclick="findPassword()" style="cursor: pointer; border: none;background-color: white">忘记密码</button></div>
								<div class="nowrap">没有账号？<button onclick="register()" style="cursor: pointer; color: #1E9FFF;border: none;background-color: white">去注册</button></div>
							</div>
						</div>
					</div>
				</div>

			</div>
		</div>

	</body>
<script type="text/javascript" src="../layui/layui.js"></script>
<script>
layui.use(['table','form','layer'],function () {
	var table = layui.table,
		form = layui.form,
		layer = layui.layer,
		$ = layui.jquery;
	form.on('submit(login)',function (data) {
		$.ajax({
			type:"get",
			url:"../userlogin",
			dataType:"json",
			data:data.field,
			success:function (res) {
				if(res.code == 200){
					console.log(res)
					sessionStorage.user = JSON.stringify(res.data) ;//session保存user信息
					//console.log(sessionStorage.user)
					//console.log(JSON.parse(sessionStorage.user).nickname)
					window.location.href="../"
				}else{
					layer.msg(res.msg,{icon:2},function () {
						changeCode();
					})

				}
			}
		})
		return false;
	})
	//return false;
})

function changeCode(){
	var img = document.getElementById("codeImg");
	img.src = "../code?date="+new Date()
}

function register(){
	window.location.href="../home/userRegister"
}
function findPassword(){
	window.location.href="../home/findPassword"
}
</script>
</html>
